package cn.well.cloud.core.auth.validator.impl;

import cn.well.cloud.core.auth.validator.IReqValidator;
import cn.well.cloud.modular.model.User;
import cn.well.cloud.modular.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;



/**
 * 账号密码验证
 *
 * @author fengshuonan
 * @date 2017-08-23 12:34
 */
@Service
public class DbValidator implements IReqValidator {

	@Autowired
    private IUserService userService;

    @Override
    public boolean validate(String userName, String password) {
    	QueryWrapper<User> userWrapper = new QueryWrapper<>();
    	userWrapper.eq("user_id", Long.valueOf(userName));
    	List<User> users = userService.list(userWrapper);
        if (users != null && users.size() > 0) {
            return true;
        } else {
            return false;
        }
    }
}
